package faceService;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qcloud.image.ImageClient;
import com.qcloud.image.common_utils.CommonFileUtils;
import com.qcloud.image.demo.Demo;
import com.qcloud.image.request.FaceNewPersonRequest;
import util.AppContast;

import java.util.logging.Level;
import java.util.logging.Logger;

import static com.qcloud.image.http.RequestBodyKey.BUCKET;

/**
 * Created by Administrator on 2017/9/28.
 */
public class CreatePerson {

    public JSONObject createPerson(String personName, String personId, String imgPath) {
        ImageClient imageClient = new ImageClient(AppContast.APP_ID, AppContast.SERCET_ID, AppContast.SERCET_KEY);
        String bucketName = BUCKET;

        String personNewName = "";
        String personNewImage = "";
        String[] groupIds = new String[1];
        groupIds[0] = "group1";
        String personTag = "test";

        try {
            personNewName = "1.jpg";
            personNewImage = CommonFileUtils.getFileContent(imgPath);
        } catch (Exception ex) {
            Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
        }

        FaceNewPersonRequest personNewReq = new FaceNewPersonRequest(bucketName, personId, groupIds, personNewName, personNewImage, personName, personTag);
        String ret = imageClient.faceNewPerson(personNewReq);

        JSONObject jsonObject = JSON.parseObject(ret);

        System.out.println("person new  ret:" + ret);

        return jsonObject;
    }
}
